# 每周获取缴费信息可能会存在数据重复的情况
# 该程序用来处理此种情况
import pymysql

online_db = pymysql.connect(host="121.4.69.146", user='root', password='xhhg@2020', port=3306, db="big_data",
                            use_unicode=True, charset='utf8')
db_cur = online_db.cursor()
# sql = "select * from annual_fee_information group by application_number,money_type having count(*) > 1"
# sql = "select * from by_payment_information group by application_number,cost_category, ticket_number having count(*) > 1"  # 查询数据库中数量大于一的数据
sql = "SELECT * FROM `registration_fee_copy1` GROUP BY fm_name, money_str HAVING count(*) > 1"

db_cur.execute(sql)
returndata = db_cur.fetchall()
print(len(returndata), returndata)
count = 0
for i in returndata:
    count += 1
    num = i[0]
    sql = f"DELETE FROM registration_fee_copy1 WHERE id = {num}"
    # sql = f"DELETE FROM by_payment_information_0530 WHERE id = {num}"
    db_cur.execute(sql)
    if count:
        online_db.commit()
        print("1")
